package com.avic.common.convertor;

import com.avic.common.constant.AppConstant;
import com.avic.common.enums.MapVideoStateEnums;
import com.avic.controller.info.MapVideoInfo;
import com.avic.dal.model.MapVideo;
import org.apache.commons.lang3.StringUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author huangsheng on 2019/2/28
 */
public class MapVideoConvertor {

    public static List<MapVideoInfo> mapVideoToMapVideoInfo(List<MapVideo> mapVideos, String viewFilePrefix) {
        List<MapVideoInfo> mapVideoInfos = new ArrayList<>();
        if (null != mapVideos && mapVideos.size() > 0) {
            mapVideos.forEach(mapVideo -> {
                MapVideoInfo mapVideoInfo = new MapVideoInfo();
                mapVideoInfo.setId(mapVideo.getId());
                mapVideoInfo.setCreateUserName(mapVideo.getCreateUserName());
                if (mapVideo.getVideoState() == MapVideoStateEnums.UPLOADED.getState()) {
                    mapVideoInfo.setVideoName(mapVideo.getVideoName());
                    mapVideoInfo.setVideoPath(viewFilePrefix + mapVideo.getVideoPath());
                    mapVideoInfo.setDataTime(StringUtils.isNotBlank(mapVideo.getUploadTime()) ?
                            StringUtils.substringBefore(mapVideo.getUploadTime(), AppConstant.MYBATIS_DATA_TIME_SEPARATOR) : StringUtils.EMPTY);
                    mapVideoInfo.setVideoState(MapVideoStateEnums.UPLOADED.getState());
                    mapVideoInfo.setVideoStateValue(MapVideoStateEnums.UPLOADED.getDescribe());
                } else {
                    MapVideoStateEnums mapVideoStateEnums = MapVideoStateEnums.getMapVideoStateEnumsByState(mapVideo.getVideoState());
                    mapVideoInfo.setVideoName(mapVideo.getVideoSourceName());
                    mapVideoInfo.setVideoPath(mapVideo.getVideoSourcePath());
                    mapVideoInfo.setDataTime(StringUtils.isNotBlank(mapVideo.getCreateTime()) ?
                            StringUtils.substringBefore(mapVideo.getCreateTime(), AppConstant.MYBATIS_DATA_TIME_SEPARATOR) : StringUtils.EMPTY);
                    mapVideoInfo.setVideoState(null != mapVideoStateEnums ? mapVideoStateEnums.getState() : 0);
                    mapVideoInfo.setVideoStateValue(null != mapVideoStateEnums ? mapVideoStateEnums.getDescribe() : StringUtils.EMPTY);
                }
                mapVideoInfos.add(mapVideoInfo);
            });
        }
        return mapVideoInfos;
    }
}
